package org.addressBook.service;

import com.google.gson.JsonObject;
import org.addressBook.bean.PageInfo;
import org.addressBook.bean.TableData;
import org.addressBook.bean.TbUser;
import org.addressBook.dao.TbUserDao;

import java.sql.SQLException;

public class TbUserService {
    // 服务类
    private TbUserDao userDao = new TbUserDao();

    // 注册
    public void regist(String name, String mail, String password) throws SQLException {
        userDao.regist(name, mail, password);
    }

    // 登录
    public TbUser login(String name, String password) throws SQLException {
        return userDao.login(name, password);
    }

    public TbUser loadAddressBook(String name, String password) throws SQLException {
        return userDao.loadAddressBook(name, password);
    }

    // 分页查询
    public PageInfo<TableData> list(String userName, Integer pageNum, Integer pageSize) {
        return userDao.list(userName, pageNum, pageSize);
    }

    // 数据到处为json
    public JsonObject jsonService(String userName) throws SQLException, ClassNotFoundException {
        return userDao.jsonDao(userName);
    }

    public void PersonInfoService(String oldName, String userName, String mail, String password) throws SQLException, ClassNotFoundException {
        userDao.PersonInfoDao(oldName, userName, mail, password);
    }
}
